<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-date-picker type="date" placeholder="开始时间" format="yyyy-MM-dd"   v-model="filters.starttime" style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="date" placeholder="结束时间" format="yyyy-MM-dd"   v-model="filters.endtime" style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="getUserLogPage">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="userslog" highlight-current-row v-loading="listLoading" border max-height="620"  style="width: 100%;">
			<el-table-column type="index" width="80" label="编号">
			</el-table-column>
			<el-table-column prop="user.username" label="登录用户名称" width="220"  >
			</el-table-column>
			<el-table-column prop="user.phonenum" label="登录用户账号" width="200"  >
			</el-table-column>
			<el-table-column prop="loginip" label="登录ip" width="200"  >
			</el-table-column>
			<el-table-column prop="logintime" label="登录时间" min-width="220"  >
			</el-table-column>
		</el-table>
		<el-pagination
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
				layout="total,sizes,prev, pager, next"
				:total="total">
		</el-pagination>
	</section>
</template>

<script>
	import util from '../../common/js/util'
	import { getUserLogPage } from '../../api/api';
    import moment from 'moment';
	export default {
		data() {
			return {
				filters: {
                    starttime:'',
                    endtime:''
				},
				userslog: [],
				total: 0,
                start:0,
                pageSize:10,
				listLoading: false,
			}
		},
		methods: {

			//获取用户列表
            getUserLogPage() {
				let para = {
                    start: this.start,
                    pageSize:this.pageSize,
                    starttime: this.filters.starttime == "" ? "" : moment(this.filters.starttime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD'),
                    endtime: this.filters.endtime == "" ? "" : moment(this.filters.endtime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD')
				};
				this.listLoading = true;
                getUserLogPage(para).then((datas) => {
					this.listLoading = false;
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.userslog = data.result;
                        this.total = data.totalCount;
                    }
				});
			}
			,handleCurrentChange:function(val){
				this.start = val - 1;
				this.getUserLogPage();
			},
			handleSizeChange:function(val){
				this.pageSize = val;
				this.getUserLogPage();
			}
		},
		mounted() {
			this.getUserLogPage();
		}
	}

</script>

<style scoped>

</style>
